package besta.moon.sql.datatype;

public class Strings {

    private int size;
    private String[] data;

    public Strings() {
        data = new String[16];
    }

    public final int size() {
        return size;
    }

    public final String get(int idx) {
        if (idx >= size) {
            throw new IndexOutOfBoundsException("Column index: " + idx + ", Size: " + size);
        }
        return data[idx];
    }

    public final void add(String descr) {
        if (size >= data.length) {
            resize(size << 1);
        }
        data[size++] = descr;
    }

    private final void resize(int newSize) {
        String[] dataNew = new String[newSize];
        System.arraycopy(data, 0, dataNew, 0, size);
        data = dataNew;
    }

    public String[] toArray() {
        String[] array = new String[size];
        System.arraycopy(data, 0, array, 0, size);
        return array;
    }

}
